#include "lolevel.h"
#include "platform.h"
#include "core.h"

static long *nrflag = (long*)0xA5FC;

#include "../../../generic/capt_seq.c"

void __attribute__((naked,noinline)) sub_FFD15B58_my(){ 
 asm volatile(
                "STMFD   SP!, {R0-R10,LR}\n"
                "MOV     R6, #0\n"
                "MOV     R4, R0\n"
                "BL      sub_FFD166AC\n"
                "MVN     R1, #0\n"
                "BL      sub_FFC19408\n"
                "MOV     R2, #4\n"
                "ADD     R1, SP, #8\n"
                "MOV     R0, #0x8A\n"
                "BL      sub_FFC5BCC0\n"
                "TST     R0, #1\n"
                "LDRNE   R1, =0x20A\n"
                "LDRNE   R0, =0xFFD15D60\n"
                "BLNE    sub_FFC0C090\n"
                "LDR     R8, =0x1993C\n"
                "LDR     R5, =0x19890\n"
                "LDRSH   R1, [R8,#0xE]\n"
                "LDR     R0, [R5,#0x74]\n"
                "BL      sub_FFCDAF78\n"
                "BL      sub_FFC3A2E0\n"
                "LDR     R2, =0xA600\n"
                "ADD     R3, R4, #0x8C\n"
                "STRH    R0, [R4,#0x88]\n"
            //  "STRD    R2, [SP]\n"
                ".long	 0xE1CD20F0\n"
                "MOV     R1, R0\n"
                "LDRH    R0, [R5,#0x4C]\n"
                "LDRSH   R2, [R8,#0xC]\n"
                "LDR     R3, =0xA5FC\n"
                "BL      sub_FFD16B98\n"
                "BL      capt_seq_hook_set_nr\n"
                "B	 sub_FFD15BCC\n"
 );
}

void __attribute__((naked,noinline)) sub_FFC4DE48_my(){ 
 asm volatile(
                "STMFD   SP!, {R3-R7,LR}\n"
                "LDR     R4, [R0,#0xC]\n"
                "LDR     R5, =0x19890\n"
                "LDR     R0, [R4,#8]\n"
                "LDR     R6, =0x820A\n"
                "ORR     R0, R0, #1\n"
                "STR     R0, [R4,#8]\n"
                "LDRH    R0, [R5]\n"
                "CMP     R0, R6\n"
                "BEQ     loc_FFC4DEE4\n"
                "LDRH    R0, [R5,#0x7E]\n"
                "CMP     R0, #3\n"
                "BEQ     loc_FFC4DF48\n"
                "LDR     R0, [R4,#0xC]\n"
                "CMP     R0, #1\n"
                "BLS     loc_FFC4DEF0\n"
                "LDRH    R0, [R5,#0x7C]\n"
                "CMP     R0, #0\n"
                "BNE     loc_FFC4DF48\n"
                "LDRH    R0, [R5,#0x78]\n"
                "CMP     R0, #2\n"
                "BNE     loc_FFC4DEFC\n"
                "BL      sub_FFD1456C\n"
                "LDRH    R0, [R5]\n"
                "CMP     R0, R6\n"
                "BEQ     loc_FFC4DEE4\n"
                "LDRH    R0, [R5,#0x7E]\n"
                "CMP     R0, #3\n"
                "BEQ     loc_FFC4DF48\n"
                "LDR     R0, [R4,#0xC]\n"
                "CMP     R0, #1\n"
                "BLS     loc_FFC4DEF0\n"
                "LDRH    R0, [R5,#0x7C]\n"
                "CMP     R0, #0\n"
                "BNE     loc_FFC4DF48\n"
                "LDRH    R0, [R5,#0x78]\n"
                "CMP     R0, #2\n"
                "BEQ     loc_FFC4DF28\n"
                "B       loc_FFC4DEFC\n"
"loc_FFC4DEE4:\n"
                "LDRH    R0, [R5,#0x7E]\n"
                "CMP     R0, #3\n"
                "BEQ     loc_FFC4DF48\n"
"loc_FFC4DEF0:\n"
                "LDRH    R0, [R5,#0x7C]\n"
                "CMP     R0, #0\n"
                "BNE     loc_FFC4DF48\n"
"loc_FFC4DEFC:\n"
                "LDRH    R0, [R5,#0x78]\n"
                "CMP     R0, #1\n"
                "BNE     loc_FFC4DF48\n"
                "LDRH    R0, [R5]\n"
                "CMP     R0, R6\n"
                "LDRNE   R0, [R4,#0xC]\n"
                "CMPNE   R0, #1\n"
                "BLS     loc_FFC4DF48\n"
                "LDR     R0, [R4,#0x10]\n"
                "CMP     R0, #1\n"
                "BNE     loc_FFC4DF48\n"
"loc_FFC4DF28:\n"
                "LDR     R3, =0x20D\n"
                "LDR     R0, =0x5698\n"
                "STR     R3, [SP]\n"
                "LDR     R0, [R0,#0xC]\n"
                "LDR     R2, =0xEA60\n"
                "LDR     R3, =0xFFC4DDC8\n"
                "MOV     R1, #0x40000000\n"
                "BL      sub_FFC51928\n"
"loc_FFC4DF48:\n"
                "BL      sub_FFC4DD2C\n"
                "MOV     R0, #2\n"
                "BL      sub_FFC49530\n"
                "BL      sub_FFD14188\n"
                "MOV     R0, R4\n"
                "BL      sub_FFD147F0\n"
                "TST     R0, #1\n"
                "MOVNE   R2, R4\n"
                "LDMNEFD SP!, {R3-R7,LR}\n"
                "MOVNE   R1, #1\n"
                "BNE     sub_FFC4C774\n"
                "BL      sub_FFD27B40\n"
                "BL      sub_FFC5BE50\n"
                "STR     R0, [R4,#0x14]\n"
                "MOV     R0, R4\n"
                "BL      sub_FFD15A70\n"
                "BL      sub_FFD16540\n"
                "MOV     R0, R4\n"
                "BL      sub_FFD15B58_my\n"         //----------->
                "BL      capt_seq_hook_raw_here\n"  //+
                "MOV     R2, R4\n"
                "MOV     R1, #1\n"
                "BL      sub_FFC4C774\n"
                "BL      sub_FFD15F94\n"
                "CMP     R0, #0\n"
                "LDRNE   R0, [R4,#8]\n"
                "ORRNE   R0, R0, #0x2000\n"
                "STRNE   R0, [R4,#8]\n"
                "LDRH    R0, [R5,#0x7E]\n"
                "CMP     R0, #3\n"
                "BEQ     loc_FFC4DFDC\n"
                "LDRH    R0, [R5,#0x7C]\n"
                "CMP     R0, #0\n"
                "LDREQH  R0, [R5,#0x78]\n"
                "CMPEQ   R0, #2\n"
                "MOVEQ   R0, R4\n"
                "LDMEQFD SP!, {R3-R7,LR}\n"
                "BEQ     sub_FFD145C0\n"
"loc_FFC4DFDC:\n"
                "LDMFD   SP!, {R3-R7,PC}\n"
 );
}


void __attribute__((naked,noinline)) CaptSeqTask() //#fs
{
	asm volatile (
                "STMFD   SP!, {R3-R7,LR}\n"
                "LDR     R6, =0x5698\n"
"loc_FFC4E2E8:\n"
                "LDR     R0, [R6,#0x10]\n"
                "MOV     R2, #0\n"
                "MOV     R1, SP\n"
                "BL      sub_FFC19658\n"
                "TST     R0, #1\n"
                "BEQ     loc_FFC4E314\n"
                "LDR     R1, =0x43F\n"
                "LDR     R0, =0xFFC4DDC8\n"
                "BL      sub_FFC0C090\n"
                "BL      sub_FFC0BE48\n"
                "LDMFD   SP!, {R3-R7,PC}\n"
"loc_FFC4E314:\n"
                "LDR     R0, [SP]\n"
                "LDR     R1, [R0]\n"
                "CMP     R1, #0x1A\n"
                "ADDLS   PC, PC, R1,LSL#2\n"
                "B       loc_FFC4E4BC\n"
"loc_FFC4E328:\n"
                "B       loc_FFC4E394\n"
"loc_FFC4E32C:\n"
                "B       loc_FFC4E39C\n"
"loc_FFC4E330:\n"
                "B       loc_FFC4E3A4\n"
"loc_FFC4E334:\n"
                "B       loc_FFC4E3B8\n"
"loc_FFC4E338:\n"
                "B       loc_FFC4E3B0\n"
"loc_FFC4E33C:\n"
                "B       loc_FFC4E3C0\n"
"loc_FFC4E340:\n"
                "B       loc_FFC4E3C8\n"
"loc_FFC4E344:\n"
                "B       loc_FFC4E3D4\n"
"loc_FFC4E348:\n"
                "B       loc_FFC4E42C\n"
"loc_FFC4E34C:\n"
                "B       loc_FFC4E3B8\n"
"loc_FFC4E350:\n"
                "B       loc_FFC4E434\n"
"loc_FFC4E354:\n"
                "B       loc_FFC4E43C\n"
"loc_FFC4E358:\n"
                "B       loc_FFC4E444\n"
"loc_FFC4E35C:\n"
                "B       loc_FFC4E44C\n"
"loc_FFC4E360:\n"
                "B       loc_FFC4E454\n"
"loc_FFC4E364:\n"
                "B       loc_FFC4E45C\n"
"loc_FFC4E368:\n"
                "B       loc_FFC4E464\n"
"loc_FFC4E36C:\n"
                "B       loc_FFC4E46C\n"
"loc_FFC4E370:\n"
                "B       loc_FFC4E474\n"
"loc_FFC4E374:\n"
                "B       loc_FFC4E47C\n"
"loc_FFC4E378:\n"
                "B       loc_FFC4E484\n"
"loc_FFC4E37C:\n"
                "B       loc_FFC4E490\n"
"loc_FFC4E380:\n"
                "B       loc_FFC4E49C\n"
"loc_FFC4E384:\n"
                "B       loc_FFC4E4A4\n"
"loc_FFC4E388:\n"
                "B       loc_FFC4E4AC\n"
"loc_FFC4E38C:\n"
                "B       loc_FFC4E4B4\n"
"loc_FFC4E390:\n"
                "B       loc_FFC4E4C8\n"
"loc_FFC4E394:\n"
                "BL      sub_FFD141D0\n"
                "BL      shooting_expo_param_override\n"  // +
                "B       loc_FFC4E3CC\n"
"loc_FFC4E39C:\n"
                "BL      sub_FFC4DE48_my\n"     //---------------->
                "B       loc_FFC4E4C8\n"
"loc_FFC4E3A4:\n"
                "MOV     R0, #1\n"
                "BL      sub_FFD14360\n"
                "B       loc_FFC4E4C8\n"
"loc_FFC4E3B0:\n"
                "BL      sub_FFD13E64\n"
                "B       loc_FFC4E4C8\n"
"loc_FFC4E3B8:\n"
                "BL      sub_FFD14178\n"
                "B       loc_FFC4E4C8\n"
"loc_FFC4E3C0:\n"
                "BL      sub_FFD14180\n"
                "B       loc_FFC4E4C8\n"
"loc_FFC4E3C8:\n"
                "BL      sub_FFD14280\n"
"loc_FFC4E3CC:\n"
                "BL      sub_FFC4C3DC\n"
                "B       loc_FFC4E4C8\n"
"loc_FFC4E3D4:\n"
                "LDR     R4, [R0,#0xC]\n"
                "BL      sub_FFD14188\n"
                "MOV     R0, R4\n"
                "BL      sub_FFD14BE0\n"
                "TST     R0, #1\n"
                "MOV     R5, R0\n"
                "BNE     loc_FFC4E414\n"
                "BL      sub_FFC5BE50\n"
                "STR     R0, [R4,#0x14]\n"
                "MOV     R0, R4\n"
                "BL      sub_FFD15A70\n"
                "MOV     R0, R4\n"
                "BL      sub_FFD15FF4\n"
                "MOV     R5, R0\n"
                "LDR     R0, [R4,#0x14]\n"
                "BL      sub_FFC5C064\n"
"loc_FFC4E414:\n"
                "BL      sub_FFD14178\n"
                "MOV     R2, R4\n"
                "MOV     R1, #8\n"
                "MOV     R0, R5\n"
                "BL      sub_FFC4C774\n"
                "B       loc_FFC4E4C8\n"
"loc_FFC4E42C:\n"
                "BL      sub_FFD142DC\n"
                "B       loc_FFC4E3CC\n"
"loc_FFC4E434:\n"
                "BL      sub_FFD14E4C\n"
                "B       loc_FFC4E4C8\n"
"loc_FFC4E43C:\n"
                "BL      sub_FFD15004\n"
                "B       loc_FFC4E4C8\n"
"loc_FFC4E444:\n"
                "BL      sub_FFD15094\n"
                "B       loc_FFC4E4C8\n"
"loc_FFC4E44C:\n"
                "BL      sub_FFD15148\n"
                "B       loc_FFC4E4C8\n"
"loc_FFC4E454:\n"
                "BL      sub_FFD153D4\n"
                "B       loc_FFC4E4C8\n"
"loc_FFC4E45C:\n"
                "BL      sub_FFD15424\n"
                "B       loc_FFC4E4C8\n"
"loc_FFC4E464:\n"
                "MOV     R0, #0\n"
                "B       loc_FFC4E488\n"
"loc_FFC4E46C:\n"
                "BL      sub_FFD155E8\n"
                "B       loc_FFC4E4C8\n"
"loc_FFC4E474:\n"
                "BL      sub_FFD1567C\n"
                "B       loc_FFC4E4C8\n"
"loc_FFC4E47C:\n"
                "BL      sub_FFD1573C\n"
                "B       loc_FFC4E4C8\n"
"loc_FFC4E484:\n"
                "MOV     R0, #1\n"
"loc_FFC4E488:\n"
                "BL      sub_FFD154A8\n"
                "B       loc_FFC4E4C8\n"
"loc_FFC4E490:\n"
                "BL      sub_FFD144AC\n"
                "BL      sub_FFC4E5E4\n"
                "B       loc_FFC4E4C8\n"
"loc_FFC4E49C:\n"
                "BL      sub_FFD15264\n"
                "B       loc_FFC4E4C8\n"
"loc_FFC4E4A4:\n"
                "BL      sub_FFD1533C\n"
                "B       loc_FFC4E4C8\n"
"loc_FFC4E4AC:\n"
                "BL      sub_FFC4DD2C\n"
                "B       loc_FFC4E4C8\n"
"loc_FFC4E4B4:\n"
                "BL      sub_FFC15C28\n"
                "B       loc_FFC4E4C8\n"
"loc_FFC4E4BC:\n"
                "LDR     R1, =0x523\n"
                "LDR     R0, =0xFFC4DDC8\n"
                "BL      sub_FFC0C090\n"
"loc_FFC4E4C8:\n"
                "LDR     R0, [SP]\n"
                "LDR     R1, [R0,#4]\n"
                "LDR     R0, [R6,#0xC]\n"
                "BL      sub_FFC193D4\n"
                "LDR     R4, [SP]\n"
                "LDR     R0, [R4,#8]\n"
                "CMP     R0, #0\n"
                "LDREQ   R0, =0xFFC4DDC8\n"
                "MOVEQ   R1, #0xFC\n"
                "BLEQ    sub_FFC0C090\n"
                "MOV     R0, #0\n"
                "STR     R0, [R4,#8]\n"
                "B       loc_FFC4E2E8\n"
    );
} //#fe
